package com.zzyl.controller.manager;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertDataPageQueryDto;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.dto.AlertRuleQueryDto;
import com.zzyl.entity.AlertRule;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Api(tags = "报警规则相关接口")
public class AlertRuleController {

    @Autowired
    private AlertRuleService alertRuleService;

    @ApiOperation(value = "新增报警规则")
    @PostMapping("/create")
    public ResponseResult create(@RequestBody AlertRuleDto dto){
        alertRuleService.create(dto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "获取单个告警规则")
    @GetMapping("/read/{id}")
    public ResponseResult getById(@PathVariable Long id){
        AlertRuleVo alertRuleVo = alertRuleService.getById(id);
        return ResponseResult.success(alertRuleVo);
    }
    @ApiOperation(value = "更新告警规则")
    @PutMapping("/update/{id}")
    public ResponseResult update(@RequestBody AlertRuleDto dto){
        alertRuleService.update(dto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "删除告警规则")
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id){
        alertRuleService.delete(id);
        return ResponseResult.success();
    }


    @ApiOperation(value = "分页获取告警规则列表")
    @GetMapping("/get-page")
    public ResponseResult queryPage(AlertRuleQueryDto dto){
        PageBean<AlertRuleVo> pageBean = alertRuleService.queryPage(dto);
        return ResponseResult.success(pageBean);
    }

    @ApiOperation("启用/禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult startOrStop(@PathVariable Long id,
                                      @PathVariable Integer status){
        alertRuleService.startOrStop(id,status);
        return ResponseResult.success();
    }
}
